# -*- coding: utf-8 -*-
"""
Created on Wed Nov 18 10:18:35 2020
Pytest
pip install pytest
pip list
pytest --version
pytest --help
anaconda
# 在 Ipython console 运行
run -m pytest 213_Software_Testing_12_PytestforPython_an_introduction.py
# 在 CMD运行
pytest 213_Software_Testing_12_PytestforPython_an_introduction.py
run -m pytest -k add 213_Software_Testing_12_PytestforPython_an_introduction.py -v
pytest --durations=0 -vv 213_Software_Testing_12_PytestforPython_an_introduction.py
pytest --durations=1 -vv 213_Software_Testing_12_PytestforPython_an_introduction.py
pytest --durations=10 -vv 214_Software_Testing_13_PytestforPython_basic_test.py
运行 anaconda prompt --》d:-- 》 cd D:\python\videos\Assignments\PandasVideos --》pytest -k add 213_Software_Testing_12_PytestforPython_an_introduction.py -v
@author: andrew
"""

import pytest


# 被测函数
def add(a, b):
    return a + b


def minus(a, b):
    return a - b


def multi(a, b):
    return a * b


def divide(a, b):
    return a / b


def isEven(a):
    if a % 2 == 0:
        return True
    else:
        return False


def funcerror(a):
    if a == 0:
        raise ValueError('Error Error')
    else:
        pass


# 测试类
class Testdemo:
    @pytest.mark.group1
    def test_add(self):
        assert 3 == add(1, 2)

    @pytest.mark.group1
    def test_addstr(self):
        assert 'ab' == add('a', 'b')

    def test_minus(self):
        assert 2 == minus(5, 3)

    @pytest.mark.group1
    def test_multi(self):
        assert 18 == multi(3, 6)

    def test_multistr(self):
        assert 'wkwkwk' == multi('wk', 3)

    def test_divide(self):
        assert 5 == divide(15, 3)


# 测试函数
@pytest.mark.group1
def test_addfailure1():
    # 该测试失败
    assert 3 == add(1, 2)


def test_minus():
    assert -1 == minus(1, 2)


def test_funcerror1():
    with pytest.raises(ValueError):
        funcerror(0)


def test_funcerror2():
    funcerror(1) == None


# 测试函数
lst1 = [(1, 2, 3), (-1, -22, -3)]


@pytest.mark.parametrize("x,y,expected", lst1)
def test_addfailure(x, y, expected):
    # 该测试失败
    assert expected == add(x, y)

# 分组测试
